package com.java.schedule.springbatch;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * TODO 类功能介绍及重点或容易混淆点的说明。
 *
 * @author: 龙小南
 * @Date: 2023/5/13 9:10
 * @Version 1.0[当前版本号]
 *
 * @version 1.0 2023/5/13 9:10 龙小南 新建类[说明]
 */

@RestController
@RequestMapping("/job")
public class Controller {

    @Resource(name = "firstJob")
    private Job firstJob;

    @Resource(name = "multiStepJob")
    private Job multiStepJobDemo;

    @Autowired
    private JobLauncher jobLauncher;

    @GetMapping("launcher/{message}")
    public String launcher(@PathVariable String message) throws Exception {
        JobParameters parameters = new JobParametersBuilder()
                .addString("message", message)
                .toJobParameters();
        // 将参数传递给任务
        jobLauncher.run(firstJob, parameters);
        return "success";
    }

}
